#include <bits/stdc++.h>
using namespace std;
int a[20];
vector<int> res;
int n;
bool fail;
int chooseafter(int x) {
  for (int i = 0; i <= 9; ++i) {
    if (i == x || !a[i]) continue;
    bool flag = true;
    // 检测能不能选这个
    a[i]--, n--;
    for (int j = 0; j <= 9; ++j) {
      if (i == j && (a[j] > n / 2) || i != j && a[j] > (n + 1) / 2) {
        flag = false;
        break;
      }
    }
    a[i]++, n++;
    if (flag) return i;  // 选定数字 i
  }
  return -1;  // 找不到了
}
int main() {
  int tc;
  cin >> tc;
  while (tc--) {
    res.clear();
    for (int i = 0; i <= 9; ++i) {
      cin >> a[i];
      n += a[i];
    }

    a[0]++, n++;  // 可视作以0开头的满足123的数字串
    if (n == 1 && a[0] == 1) {
      cout << 0 << endl;
    } else if (a[0] > n / 2) {
      cout << -1 << endl;
    } else {
      bool ok = true;
      int prev = 0;
      while (n--) {
        int ne = chooseafter(prev);
        if (ne != -1) {
          a[ne]--;
          prev = ne;
          res.push_back(ne);
        } else {
          ok = false;
          break;
        }
      }
      if (ok) {
        for (auto el : res) {
          cout << char(el + '0');
        }
        cout << endl;
      } else {
        cout << -1 << endl;
      }
    }
  }
}
